package cn.anecansaitin.industrialization_expansion.common.item;

import cn.anecansaitin.industrialization_expansion.ExtensionLoader;
import cn.anecansaitin.industrialization_expansion.ModConstant;
import cn.anecansaitin.industrialization_expansion.common.CommonEventHooks;
import net.minecraft.item.Item;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;

import java.util.List;

public class ItemRegister {
    public static final DeferredRegister<Item> ITEM = DeferredRegister.create(ForgeRegistries.ITEMS, ModConstant.MOD_ID);

    public static final RegistryObject<Item> TOOL = ITEM.register("tool", ModifiedTool::new);
    public static final RegistryObject<Item> MODULE_TEMPLATE = ITEM.register("module_template", ModuleTemplate::new);
    public static final RegistryObject<Item> TEST = ITEM.register("test", TestItem::new);

    public static void registry(IEventBus bus) {
        //额外的物品注册
        //工具
        CommonEventHooks.fireToolRegisterEvent();
        List<Item> tools = ExtensionLoader.TOOLS;

        for (int i = 0, toolsSize = tools.size(); i < toolsSize; i++) {
            Item tool = tools.get(i);
            ITEM.register(ExtensionLoader.TOOL_IDS.get(i), () -> tool);
        }

        //部件
        CommonEventHooks.fireModuleRegisterEvent();
        List<Item> modules = ExtensionLoader.MODULES;

        for (int i = 0, modulesSize = modules.size(); i < modulesSize; i++) {
            Item module = modules.get(i);
            ITEM.register(ExtensionLoader.MODULE_IDS.get(i), () -> module);
        }

        ITEM.register(bus);
    }
}
